/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletContext;

import org.springframework.web.context.support.ServletContextResource;

/**
 * 
 * @author haolw
 * @time 2017/08/30
 */
public abstract class ServletContextSupport {
	protected static ServletContext servletContext;

	public static ServletContext getServletContext() {
		return servletContext;
	}

	public static File getContextFile(String filePath) {
		ServletContextResource contextResource = new ServletContextResource(servletContext, filePath);
		File targetFile;
		try {
			targetFile = contextResource.getFile();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		return targetFile;
	}

}
